package com.hr.ping.job;

import com.hr.ping.service.PingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

@Component
public class PingScheduler {

    private static final Logger log = LoggerFactory.getLogger(PingScheduler.class);
    private final PingService pingService;

    public PingScheduler(PingService pingService) {
        this.pingService = pingService;
    }

    @Scheduled(fixedRate = 100)
    public void schedulePing() {
        Mono<String> pingMono = pingService.ping();
        pingMono.subscribe(response -> log.info("Ping response: {}", response));
    }
}
